package com.qf.controller;

import com.alipay.api.AlipayApiException;
import com.qf.pojo.vo.Orders;
import com.qf.service.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    PayService payService;

    @RequestMapping("/pay")
    public String payOrder(HttpServletRequest request, HttpServletResponse response, @RequestBody Map map)  {
        try {
            System.out.println("map = " + map);
            String pay = payService.pay(request, response, map);
            System.out.println("pay = " + pay);
            return pay;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }

    @RequestMapping("/notifyUrl")
    public void notifyUrl(HttpServletRequest request,HttpServletResponse response) throws AlipayApiException {
        payService.notifyUrl(request,response);
    }
}
